package com.mall.huohuo.result;

import com.mall.huohuo.enums.ResultEnum;
import org.springframework.util.Assert;

public class Result<T> {
    private T data;
    private Integer code;
    private Boolean success;
    private String message;

    private String requestId;

    public static Result failure(String message, Integer code) {
        Assert.notNull(code, "failure code is not null");
        return new Result().setSuccess(Boolean.FALSE).setMessage(message).setCode(code);
    }

    public static Result exception(String exceptionMessage,Integer code) {
        Assert.notNull(exceptionMessage,"failure exceptionMessage is not null");
        Assert.notNull(code,"failure code is not null");
        return new Result().setSuccess(Boolean.FALSE).setMessage(exceptionMessage).setCode(code);
    }


    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public Result<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public Result<T> setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result<T> setMessage(String message) {
        this.message = message;
        return this;
    }
    public static <T> Result success(T data){
        return new Result().
                setData(data)
                .setSuccess(true)
                .setCode(ResultEnum.SUCCESS.getCode());
    }




}
